Expose describe functions and use docstrings as block names#55
Merged
Conversation
Add a public function get_describe_functions() so that reporting plugins can access the describe functions enclosing a test item, and an opt-in ini option describe_docstrings that uses docstrings as names for describe blocks in test reports. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changing
This PR adds two closely related features for better test reporting:
Public API:
get_describe_functions(item)A new public function exported from
pytest_describethat returns the describe functions enclosing a collected test item, starting with the outermost block. Reporting plugins (e.g. pytest-spec) can use it to access the original describe functions and their docstrings.This supersedes #53 — many thanks to @joshuaprior for the original proposal and the pytest-spec integration. The implementation here uses a simple documented helper based on
item.listchain()instead of attaching methods to the items at collection time.Opt-in docstring names for describe blocks
A new boolean ini option
describe_docstrings(default: off). When enabled, describe blocks that have a docstring are reported under the first line of that docstring instead of the function name:This implements the suggestion of @undeadgrishnackh in #41. The option is opt-in because the names become part of the node IDs, which would otherwise change for existing test suites that happen to have docstrings.
Closes #41, closes #53.
Both features are covered by new tests and documented in the README.
🤖 Generated with Claude Code